import 'package:flutter/material.dart';
import 'package:flutter_syt/datas/user_info.dart';
import 'package:flutter_syt/theme/font_styles.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';

// class UserRole {
//   late String id;
//   late String name;
//   UserRole(this.id, this.name);
// }

class PersonInfoEntity {
  late String username;
  late String score;
  late String url;
  late List<UserRole> role;
  late String level; // 会员等级
  late String count; // 折扣
  late String multipleNumber; // 倍数
  late GestureTapCallback? onTap;

  PersonInfoEntity(this.username, this.score, this.url, this.role, this.level,
      this.count, this.multipleNumber);
}

class PersonInfoCard extends StatelessWidget {
  final PersonInfoEntity entity;
  final Widget? child;
  final String? rightButtonText;
  final GestureTapCallback? onRightButtonTap;
  const PersonInfoCard(
    this.entity, {
    Key? key,
    this.child,
    this.rightButtonText,
    this.onRightButtonTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      // height: 200,
      margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(12),
        color: ThemeColor.bkColorFFFFFF,
        boxShadow: [
          BoxShadow(
            color: Color(0xffE0E0E0).withOpacity(0.5),
            blurRadius: 5.0,
            offset: Offset(3.0, 0),
          ),
        ],
      ),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.fromLTRB(15, 20, 15, 15),
            child: Row(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Stack(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 14),
                      width: 60,
                      height: 60,
                      child: CircleAvatar(
                        radius: 60,
                        backgroundImage: NetworkImage(entity.url),
                      ),
                    ),
                  ],
                ),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Expanded(
                              child: Text(
                            entity.username,
                            textAlign: TextAlign.left,
                            style: FontStyles.headerTextStyle_24,
                            softWrap: false,
                            overflow: TextOverflow.ellipsis,
                            maxLines: 2,
                          )),
                        ],
                      ),
                      Row(
                        children: entity.role
                            .map(
                              (e) => Container(
                                margin: EdgeInsets.only(top: 5, right: 5),
                                padding: EdgeInsets.only(left: 5, right: 5),
                                alignment: Alignment.center,
                                // width: 45,
                                height: 18,
                                decoration: BoxDecoration(
                                  gradient: LinearGradient(
                                    // begin: Alignment.topRight,
                                    // end: Alignment.bottomLeft,
                                    colors: [
                                      Color(0xffFFCE00),
                                      Color(0xffFF9900),
                                    ],
                                  ),
                                  borderRadius: BorderRadius.circular(8),
                                ),
                                child: Text(
                                  e.name,
                                  style: TextStyle(
                                    fontSize: 10,
                                    color: ThemeColor.bkColorFFFFFF,
                                  ),
                                ),
                              ),
                            )
                            .toList(),
                      )

                      // Text(
                      //   '剩余积分:${entity.score}',
                      //   textAlign: TextAlign.left,
                      //   style: TextStyle(
                      //     color: ThemeColor.colorBlack80,
                      //     fontSize: 12,
                      //     height: 2,
                      //   ),
                      // ),
                    ],
                  ),
                ),
                Container(
                  width: 50,
                  height: 24,
                  child: OutlinedButton(
                    child: Text(
                      '$rightButtonText',
                      style: FontStyles.headerTextStyle_12,
                    ),
                    style: OutlinedButton.styleFrom(
                      padding: EdgeInsets.all(0),
                      alignment: Alignment.center,
                      // primary: ThemeColor.colorBlack100,
                      backgroundColor: ThemeColor.primaryColor,
                      side: BorderSide(
                        color: ThemeColor.primaryColor,
                        width: 1,
                      ),
                      shape: const RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                    ),
                    onPressed: ClickUtils.debounce(() => onRightButtonTap),
                  ),
                ),
                // GestureDetector(
                //   onTap: onRightButtonTap,
                //   child: Container(
                //     width: 50,
                //     height: 24,
                //     decoration: BoxDecoration(
                //       borderRadius: BorderRadius.circular(4),
                //       color: ThemeColor.colorFDD000,
                //     ),
                //     child: Text(
                //       rightButtonText ?? '',
                //       textAlign: TextAlign.center,
                //     ),
                //   ),
                // ),
              ],
            ),
          ),
          Container(
            child: child,
          ),
        ],
      ),
    );
  }
}
